﻿package mortal.game.scene3D.map3D.mapShader
{
    import baseEngine.core.*;
    import baseEngine.system.*;
    import com.gengine.resource.*;
    import frEngine.manager.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.filters.fragmentFilters.*;

    public class MapFragmentFilter extends FragmentFilter
    {
        public var bottomTexture:Texture3D;
        public var _texture2:Texture3D;

        public function MapFragmentFilter(param1:Texture3D)
        {
            super([param1]);
            this.bottomTexture = param1;
            this._texture2 = Global3D.nullAtfTexture;
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            param1.getParamByName("{texture1}", false).value = this.bottomTexture;
            param1.getParamByName("{texture2}", false).value = this._texture2;
            return;
        }// end function

        override public function get programeId() : String
        {
            return "mapTextureFilter:" + FilterBase.ATLFormat[this.bottomTexture.format];
        }// end function

        override public function clone() : FilterBase
        {
            var _loc_1:* = Resource3dManager.instance.getTexture3d(this.bottomTexture.request, this.bottomTexture.mipMode);
            var _loc_2:* = new MapFragmentFilter(_loc_1);
            return _loc_2;
        }// end function

        override public function createVertexCode(param1:Program3dRegisterInstance, param2:int) : String
        {
            var _loc_3:* = new Array();
            _loc_3.push(new ToBuilderInfo("va0", FilterName.UV, false, 2));
            _loc_3.push(new ToBuilderInfo("vf0", FilterName.V_UvOriginalPos, false, 1));
            var _loc_4:String = "mov           vf0         \t va0        \t\t\t\t\n";
            _loc_4 = param1.toBuild(_loc_4, _loc_3);
            return _loc_4;
        }// end function

        override public function createFragmentUvCoord(param1:Program3dRegisterInstance) : String
        {
            var _loc_2:* = new Array();
            _loc_2.push(new ToBuilderInfo("ft0", FilterName.F_UVPostion, false, 1));
            var _loc_3:* = FilterName.V_UvOriginalPos;
            var _loc_4:* = "mov           ft0         \t " + _loc_3 + "        \t\t\t\t\n";
            _loc_4 = param1.toBuild(_loc_4, _loc_2);
            return _loc_4;
        }// end function

        override public function createFragmentColor(param1:Program3dRegisterInstance, param2:Boolean) : String
        {
            var _loc_3:* = new Array();
            _loc_3.push(new ToBuilderInfo("fc0", "{F_const}", false, 1, [0, 0, 256 / 1024, 256 / 512]));
            _loc_3.push(new ToBuilderInfo("fs0", "{texture1}", false, 1, this.bottomTexture));
            _loc_3.push(new ToBuilderInfo("fs1", "{texture2}", false, 1, this.bottomTexture));
            var _loc_4:* = FilterName.F_UVPostion;
            var _loc_5:String = "";
            _loc_5 = _loc_5 + ("tex           {output}  " + _loc_4 + ".xy    " + getSmapleString("fs0", this.bottomTexture.format, param2, this.bottomTexture.mipMode) + "\t\n");
            if (this.bottomTexture.format == TextureFormat.FORMAT_COMPRESSED_ALPHA)
            {
                _loc_5 = _loc_5 + "mul\t\t\t{output}\t   {output}\t\t\t{output}.w\t \n";
            }
            _loc_5 = _loc_5 + ("mul           ft0       fc0.zw    " + _loc_4 + ".xy\t\t\n");
            _loc_5 = _loc_5 + "add           ft0.xy    fc0.xy    ft0.xy\t\t\t\t\t\n";
            _loc_5 = _loc_5 + ("tex           ft1       \t\tft0.xy    " + getSmapleString("fs1", this._texture2.format, true, this._texture2.mipMode) + "\t\n");
            _loc_5 = _loc_5 + "mul\t\t\t ft1\t   \t\t    ft1\t\t\t\tft1.w\t \t\t\t\n";
            _loc_5 = _loc_5 + "sub           ft1.w\t\t\t\t{fcConst1}.z\t{output}.w    \t\t\n";
            _loc_5 = _loc_5 + "mul           ft1.xyz       \tft1    \t\t\tft1.w\t\t\t\t\n";
            _loc_5 = _loc_5 + "add           {output}     \t\t{output}    \tft1\t\t\t\t\t\n";
            _loc_5 = param1.toBuild(_loc_5, _loc_3);
            return _loc_5;
        }// end function

    }
}
